import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import get from '@dfeidao/atom-web/local/get';
import set from '@dfeidao/atom-web/local/set';
import javadsd from '@dfeidao/atom-web/msg/javadsd';
import render from '@dfeidao/atom-web/render/render';
import a017 from './a017';
import P03 from './P03';
interface B {
	docDataStore: {
		master: {
			dataArray: [{
				no: string
				formid: string;
				grid_1: {
					dataArray: [
						{
							no: string;
							formid: string;
							formname: string;
							action_name: string;
							action_keyword: string;
						}
					]
				}
			}]
		};
	};
}
export default async function a008(fd: IFeidaoAiBrowserComponent) {
	// const userinf = await whoami();
	const productid1 = get(fd, 'productid');
	const select1 = fd.data.node.querySelector<HTMLSelectElement>('[select]');
	const index = select1.options.selectedIndex;
	const client_type1 = select1.options[index].value;
	const condition = {
		param: {
			productid: productid1,
			client_type: client_type1
		}
	};
	set(fd, 'client_type', client_type1);
	const ret = await javadsd('12', '12', 'smart_securitydsd0000001', condition) as B;
	const array = new Array();
	ret.docDataStore.master.dataArray.forEach((i, idex) => {
		if (i.grid_1.dataArray.length > 0) {
			i.grid_1.dataArray.forEach((j) => {
				j.no = j.formid;
				j.formid = j.formid + j.action_keyword;
				j.formname = j.action_name;
				array.push(j);
			});
		}
		delete i.grid_1;
		i.no = '';
		if (!i.formid) {
			i.formid = JSON.stringify(idex);
		}
		array.push(i);
	});
	render(fd, JSON.stringify(array), P03, 'P03', 'inner');
	const level = get(fd, 'level_no111') as string;
	if (level) {
		await a017(fd, { level });
	}
}
